const path = require('path');
const webpack =require('webpack');
const baseConfig = require('./webpack.base');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const prodConfig = {
    mode: 'production',
    entry: baseConfig.entry,
    output: baseConfig.output,
    module: baseConfig.module,
    resolve: baseConfig.resolve,
    devtool: 'inline-source-map', // 将打包后的代码映射到原始代码，方便找出错误信息
    plugins: [
        ...baseConfig.plugins,
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: './index.html',
            inject: true,
            minify: {
                removeComments: true,
                collapseWhitespace: true,
                removeAttributeQuotes: false
            }
        }),

        new CleanWebpackPlugin({
            root: path.resolve(__dirname, '../dist/src/'),   //根目录
            verbose:  true,        　　　　　　　　　　//开启在控制台输出信息
        }),
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify('development')
        })
    ],
    optimization: baseConfig.optimization
};
module.exports = prodConfig;
